/* Araujo Heiker CI. 19726991
 * Goyo Willandher CI.20666542
 * Rodriguez Rafael CI.20009872
 * Williams Roman CI.20016812 
 * Morett Gilberth CI.20929667*/

package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.ImageIcon;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import javax.swing.WindowConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PantallaDespacho extends javax.swing.JFrame {
	private JPanel jPnlDespacho;
	private JLabel jLblTitulo;
	private JButton jBtnDespachar;
	private JLabel jLabelImagen;
	private JTable jTblDespacho;
	private JScrollPane jScrollPnDespacho;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				PantallaDespacho inst = new PantallaDespacho();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public PantallaDespacho() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("Sistema de Almacen-Pedidos por Despachar");
			{
				jPnlDespacho = new JPanel();
				getContentPane().add(jPnlDespacho, BorderLayout.CENTER);
				jPnlDespacho.setLayout(null);
				jPnlDespacho.setBackground(new java.awt.Color(255,255,255));
				{
					jScrollPnDespacho = new JScrollPane();
					jPnlDespacho.add(jScrollPnDespacho);
					jScrollPnDespacho.setBounds(68, 81, 708, 142);
					{
						DefaultTableModel jTblDespachoModel = 
								new DefaultTableModel(
										new String[][] { },
										new String[] { "Codigo Pedido", "Id Cliente" , "Nombre Cliente" });
						jTblDespacho = new JTable();
						jScrollPnDespacho.setViewportView(jTblDespacho);
						jTblDespacho.setModel(jTblDespachoModel);
					}
				}
				{
					jLblTitulo = new JLabel();
					jPnlDespacho.add(jLblTitulo);
					jLblTitulo.setText("Lista de Pedidos por Despachar");
					jLblTitulo.setBounds(276, 33, 311, 22);
					jLblTitulo.setFont(new java.awt.Font("Bitstream Charter",0,20));
				}
				{
					jBtnDespachar = new JButton();
					jPnlDespacho.add(jBtnDespachar);
					jPnlDespacho.add(getJLabelImagen());
					jBtnDespachar.setText("Despachar");
					jBtnDespachar.setBounds(335, 287, 144, 22);
				}
			}
			pack();
			this.setSize(819, 397);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void agregarListener(ActionListener accion){
		
		jBtnDespachar.addActionListener(accion);
		
	}

	public void mostrarMensaje(String mensaje){
		JOptionPane.showMessageDialog(this, mensaje);
	}
	
	public void cargarListado(AbstractTableModel atm) {
		jTblDespacho.setModel(atm);
	}

	public int getCantidadFilas() {
		return this.jTblDespacho.getRowCount();
	}

	public void agregarFilaDeposito(Vector<String> pedido) {
		
		DefaultTableModel modelop = (DefaultTableModel) this.jTblDespacho.getModel();
		modelop.addRow(pedido);
	}
	
	public String obtenerCodigoDespachoFilaSeleccionada(){
		int fila = jTblDespacho.getSelectedRow();
		String codPedido = (String) jTblDespacho.getModel().getValueAt(fila, 0);
		return codPedido;
	}
	
	public int nroFilasSeleccionadas() {
		return jTblDespacho.getSelectedRowCount();
	}
	
	private JLabel getJLabelImagen() {
		if(jLabelImagen == null) {
			jLabelImagen = new JLabel();
			jLabelImagen.setBounds(0, 33, 50, 348);
			jLabelImagen.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/fondo7.jpg")));
		}
		return jLabelImagen;
	}

}